<?php
class Mimgconfig extends CI_Model {
	function __construct() {
		parent::__construct ();
	}
	function getImgConfig() {
		$arr = array ();
		$sql = "select * from tbimgconfig where id = 1";
		$query = $this->db->query ( $sql );
		foreach ( $query->result () as $row ) {
			$arr ["id"] = $row->id;
			$arr ["imgtext"] = $row->imgtext;
			$arr ["imgurl"] = $row->imgurl;
			$arr ["capacity"] = $row->capacity;
			$arr ["location"] = $row->location;
			$arr ["limitsize"] = $row->limitsize;
			$arr ["imgtype"] = $row->imgtype;
			$arr ["isvalid"] = $row->isvalid;
		}
		return $arr;
	}
	function setImgConfig($imgtext, $capacity, $location, $limitsize, $imgtype, $isvalid) {
		$this->initImgConfig ();
		
		$sql = "update tbimgconfig set imgtext = ?,capacity = ?,location = ?,limitsize = ?,imgtype = ?,isvalid = ?
								where id = 1";
		$this->db->query ( $sql, array (
				"$imgtext",
				"$capacity",
				"$location",
				"$limitsize",
				"$imgtype",
				"$isvalid" 
		) );
	}
	function saveImgConfig($url) {
		$this->initImgConfig ();
		$sql = "update tbimgconfig set imgurl = ? where id = 1";
		
		$this->db->query ( $sql, array (
				"$url" 
		) );
	}
	function initImgConfig() {
		$sql = "select * from tbimgconfig where id = 1";
		$query = $this->db->query ( $sql );
		$exists = false;
		foreach ( $query->result () as $row ) {
			$exists = true;
		}
		if ($exists == false) {
			$sql = "insert into tbimgconfig(id) values(1)";
			$this->db->query ( $sql );
		}
	}
}
?>